#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "Action.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class Behavior;
class InputPin;
class OutputPin;

/// <summary>
/// ReduceAction
/// A ReduceAction is an Action that reduces a collection to a single value by
/// repeatedly combining the elements of the collection using a reducer Behavior.
/// </summary>
class UMLMODEL_EXPORT ReduceAction : public Action {

public: // Constructors and destructors
    explicit ReduceAction(const QString& umlType="uml::ReduceAction");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Properties
    /// <summary>
    /// collection getter
    /// The InputPin that provides the collection to be reduced.
    /// </summary>
    shared_ptr<InputPin> collection() const;

    /// <summary>
    /// collection setter
    /// The InputPin that provides the collection to be reduced.
    /// </summary>
    void setCollection(shared_ptr<InputPin> value);

    /// <summary>
    /// isOrdered getter
    /// Indicates whether the order of the input collection should determine the order
    /// in which the reducer Behavior is applied to its elements.
    /// </summary>
    bool isOrdered() const;

    /// <summary>
    /// isOrdered setter
    /// Indicates whether the order of the input collection should determine the order
    /// in which the reducer Behavior is applied to its elements.
    /// </summary>
    void setIsOrdered(bool value);

    /// <summary>
    /// reducer getter
    /// A Behavior that is repreatedly applied to two elements of the input collection
    /// to produce a value that is of the same type as elements of the collection.
    /// </summary>
    shared_ptr<Behavior> reducer() const;

    /// <summary>
    /// reducer setter
    /// A Behavior that is repreatedly applied to two elements of the input collection
    /// to produce a value that is of the same type as elements of the collection.
    /// </summary>
    void setReducer(shared_ptr<Behavior> value);

    /// <summary>
    /// result getter
    /// The output pin on which the result value is placed.
    /// </summary>
    shared_ptr<OutputPin> result() const;

    /// <summary>
    /// result setter
    /// The output pin on which the result value is placed.
    /// </summary>
    void setResult(shared_ptr<OutputPin> value);

private: // Fields
    /// <summary>
    /// collection
    /// The InputPin that provides the collection to be reduced.
    /// </summary>
    shared_ptr<InputPin> collection_;

    /// <summary>
    /// isOrdered
    /// Indicates whether the order of the input collection should determine the order
    /// in which the reducer Behavior is applied to its elements.
    /// </summary>
    const static bool isOrdered_default_;
    bool isOrdered_= isOrdered_default_;

    /// <summary>
    /// reducer
    /// A Behavior that is repreatedly applied to two elements of the input collection
    /// to produce a value that is of the same type as elements of the collection.
    /// </summary>
    shared_ptr<Behavior> reducer_;

    /// <summary>
    /// result
    /// The output pin on which the result value is placed.
    /// </summary>
    shared_ptr<OutputPin> result_;

};

} // namespace uml
